home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / mac / sftksrcs.hqx / SoftKiss.src.1.8 / init / CShowINIT_PROC.c next >
Encoding:
C/C++ Source or Header  |  1992-06-25  |  6.1 KB  |  163 lines

  1. /*
  2.  * begin mods by aw0g for use softkiss
  3.  */
  4. #define main ShowINIT
  5. #include "CShowINIT_PROC.h"
  6. /*
  7.  * end mods by aw0g for use in softkiss
  8.  */
  9.  
  10. /*-------------------------------------------------------------------------
  11.   Filename: CShowINIT_PROC.c
  12.   Color ShowINIT, for use with LightspeedC
  13.   This translation by Ken McLeod (thecloud@dhw68k.cts.com)
  14.   Version of: Thursday, April 6, 1989 3:30:00 PM
  15.  
  16.   INIT notification routine
  17.   by Paul Mercer, Darin Adler, and Paul Snively from an idea by Steve Capps
  18.   Version of: Friday, July 15, 1988 12:08:09 AM    (1.1B1)
  19.     -revved back to previous calling interface.
  20.     -you only need to call ShowINIT now and due to popular demand,
  21.      deltaX is back!
  22.     -also due to popular demand, color icons are now done automatically.
  23.     -note that the color icon is only used if 4 bits or more is available on
  24.      the main graphics device; the normal #ICN is used for all other cases.
  25.   
  26.   Build & save this file as a 'PROC' resource, and include it in your
  27.   INIT's resource file.  Use the following code within your INIT to load
  28.   the 'PROC' and call CShowINIT:
  29.   
  30.       Handle    procH;
  31.       
  32.       if ((procH = GetResource('PROC', PROC_ID)) != 0L)    {
  33.             HLock(procH);
  34.             CallPascal(ICON_ID, -1, *procH);
  35.             HUnlock(procH);
  36.         }
  37.  
  38.   -------------------------------------------------------------------------*/
  39.  
  40. /* #include <MacHeaders> */
  41. /* #include <Color.h> */
  42.  
  43. typedef struct QuickDraw {       /* struct to hold QuickDraw globals */
  44.   char private[76];
  45.   long randSeed;
  46.   BitMap screenBits;
  47.   Cursor arrow;
  48.   Pattern dkGray;
  49.   Pattern ltGray;
  50.   Pattern gray;
  51.   Pattern black;
  52.   Pattern white;
  53.   GrafPtr thePort;
  54. } QuickDraw;
  55.  
  56. /*extern short ROM85 : 0x28E;*/
  57. /*extern GDHandle MainDevice : 0x8A4;*/
  58.  
  59. extern short myH : 0x92C;        /* CurApName+28   */
  60. extern short myCheck: 0x92E;     /* CurApName+30   */
  61.  
  62. #define  firstX         8        /* left margin - offset to first icon */
  63. #define  bottomEdge     8        /* this far from bottom of screen */
  64. #define  iconWidth      32       /* size of icon (square normally) */
  65. #define  defaultMoveX   40       /* default amount to move icons */
  66. #define  checksumConst  0x1021   /* constant used for computing checksum */
  67. #define  minColorDepth  4        /* min. bits/pixel for drawing color icons */
  68. #define  maskOffset     128      /* offset to mask in ICN# resource */
  69. #define  iconRowBytes   32/8     /* 32/8 bits */
  70. #define  hasCQDBit      6        /* bit in ROM85 cleared if CQD available */
  71.  
  72. /*-------------------------------------------------------------------------
  73.   Display the ICN# (cicn when in 4 bit mode or higher) specified by iconID
  74.   and move the pen horizontally by moveX.  Pass a -1 in moveX to move the
  75.   standard amount (40 pixels).
  76.  
  77.   pascal void ShowINIT(iconID, moveX)
  78.     short iconID, moveX;
  79.     extern;
  80.  
  81.   -------------------------------------------------------------------------*/
  82.  
  83. pascal void main(iconID, moveX)
  84. short iconID, moveX;
  85. {
  86.   Handle  theIconHdl;                      /* handle to the icon (or cicn) */
  87.   short     dh;                         /* for calculating horizontal offset */
  88.   short  colorFlag;             /* set if drawing a color icon */
  89.   short  theDepth;              /* depth of main screen; used for CQD only */
  90.   GDHandle theMainDevice;       /* handle to main screen device; CQD only */
  91.   Rect srcRect, destRect;       /* source & destination rectangles */
  92.   BitMap myBitMap;              /* icon bitmap; used for b/w icon only */
  93.   GrafPort myPort;              /* port we draw into */
  94.   QuickDraw qdGlobals;             /* our own personal QD globals... */
  95.   Ptr localA5;                  /* pointer to qdGlobals.thePort */
  96.   Ptr    savedA5;                                    /* storage for saved contents of A5 */
  97.   
  98.   asm {
  99.     move.l  A5,savedA5                    /* save "real" QD globals ptr */
  100.     lea          localA5,A5                    /* set up A5 to point to our globals */
  101.     move.l  A5,CurrentA5
  102.   }
  103.   InitGraf(&qdGlobals.thePort);    /* initialize our qdGlobals structure */
  104.   OpenPort(&myPort);
  105.   colorFlag = 0;                                /* default: no color */
  106.  
  107.   if (!(BitTst(&ROM85, 7-hasCQDBit))) {    /* does CQD exist? */
  108.     theMainDevice = MainDevice;                    /* yes; get handle to main device */
  109.         theDepth = (*(*theMainDevice)->gdPMap)->pixelSize;
  110.     if (theDepth >= minColorDepth)    {        /* deep enough to draw in color? */
  111.       if ((theIconHdl = (Handle)GetCIcon(iconID)) != 0L)
  112.         colorFlag = 1;                                    /* found a color icon; set flag */
  113.     }
  114.   }
  115.  
  116.   if (!(colorFlag))    {  /* no CQD, insufficient depth, or lack of 'cicn' */
  117.     if (!(theIconHdl = GetResource('ICN#',iconID))) {
  118.       SysBeep(3);  /* can't get b/w icon; signal error and bail out */
  119.       goto out;
  120.     }
  121.   }
  122.   dh = (myH << 1) ^ checksumConst;           /* checksum to find dh */
  123.   myH = ((dh == myCheck) ? (myH):(firstX));  /* reset if necessary */
  124.   /* notice that we stored the new horizontal value directly back into
  125.       the low-memory 'myH' location, rather than using a temporary variable.
  126.       This is the way the original ShowINIT works, and IconWrap relies on it. */
  127.  
  128.   destRect.bottom = myPort.portRect.bottom - bottomEdge;
  129.   destRect.left = myPort.portRect.left + myH;
  130.   destRect.top = destRect.bottom - iconWidth;
  131.   destRect.right = destRect.left + iconWidth;
  132.  
  133.   if (colorFlag) {                                /* draw color icon */
  134.       PlotCIcon(&destRect,(CIconHandle)theIconHdl);
  135.     DisposCIcon((CIconHandle)theIconHdl);
  136.   }
  137.   else {                                          /* draw b/w icon */
  138.     HLock(theIconHdl);
  139.     srcRect.top = srcRect.left = 0;
  140.     srcRect.bottom = srcRect.right = iconWidth;
  141.     myBitMap.rowBytes = iconRowBytes;
  142.     myBitMap.bounds = srcRect;
  143.     myBitMap.baseAddr = *theIconHdl + maskOffset; /* punch hole with mask */
  144.     CopyBits(&myBitMap, &myPort.portBits, &srcRect, &destRect, srcBic, 0L);
  145.     myBitMap.baseAddr = *theIconHdl;              /* now draw the icon */
  146.     CopyBits(&myBitMap, &myPort.portBits, &srcRect, &destRect, srcOr, 0L);
  147.     HUnlock(theIconHdl);
  148.     ReleaseResource(theIconHdl);
  149.   }
  150.   myH += ((moveX == -1) ? (defaultMoveX):(moveX));  /* advance for next time */
  151.   myCheck = (myH << 1) ^ checksumConst;             /* calc new checksum */
  152.  
  153. out:
  154.   ClosePort(&myPort);
  155.   asm {
  156.     move.l  savedA5,A5
  157.     move.l  A5,CurrentA5
  158.   }
  159.  
  160. }
  161.  
  162. /*-------------------------------------------------------------------------*/
  163.